#include "plt_dev.h"

struct led_config{
	//时钟控制位偏移
	uint32_t rcc_pos;
	//引脚号
	uint32_t pin_num;
};

struct led_config led_config = {
	.rcc_pos =  8,
	.pin_num = 0,
};

//资源列表
static struct resource led_resource[] = {
	[0] = DEFINE_RES_MEM(RCC_MP_AHB4ENSETR, 4),
	[1] = DEFINE_RES_MEM(GPIOI_MODER, 4),
	[2] = DEFINE_RES_MEM(GPIOI_OTYPER, 4),
	[3] = DEFINE_RES_MEM(GPIOI_OSPEEDR, 4),
	[4] = DEFINE_RES_MEM(GPIOI_PUPDR, 4),
	[5] = DEFINE_RES_MEM(GPIOI_BSRR, 4),
};

//卸载时执行
static void led_release(struct device *dev)
{
	struct platform_device *pdev = to_platform_device(dev);

	printk("%s release\r\n", pdev->name);
}

//平台设备
static struct platform_device led_dev = {
	.name = "myled",							//设备名称
	.id = 0,									//ID，用于区分不同的设备
	.num_resources = ARRAY_SIZE(led_resource),	//资源数量
	.resource = led_resource,					//资源列表
	.dev = {
		.release = led_release,					//设备卸载函数
		.platform_data = &led_config,			//设备私有数据
	},
};

static int __init plt_dev_init(void)
{
	int err;
	//注册平台设备
	err = platform_device_register(&led_dev);
	return err;
}

static void __exit plt_dev_exit(void)
{
	//注销平台设备
	platform_device_unregister(&led_dev);
}

module_init(plt_dev_init);
module_exit(plt_dev_exit);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("LF");
MODULE_DESCRIPTION("pled_dev");
